#-*- coding:UTF-8 -*-
'''
Created on 2012-7-17
Socket Client
@author: Administrator
'''
from socket import *
from time import ctime

HOST = '127.0.0.1'
PORT = 21567
BUFSIZE = 1024

def testTcp():
    tcpCliSock = socket(AF_INET, SOCK_STREAM)
    tcpCliSock.connect_ex((HOST, PORT))
    
    while True:
        data = raw_input('>')
        if not data:
            break
        tcpCliSock.send(data);
        data = tcpCliSock.recv(BUFSIZE)
        if not data:
            break
        print data
    tcpCliSock.close()

def testUdp():
    udpSerSock = socket(AF_INET, SOCK_DGRAM) 
    
    try:
        while True: 
            data = raw_input('>')
            if not data:
                break
            udpSerSock.sendto(data, (HOST, PORT))
            data, ADDR = udpSerSock.recvfrom(BUFSIZE)
    
            if not data:
                break  
    except EOFError, e:
        print e,
    except KeyboardInterrupt, k:
        print k,
    finally:    
        udpSerSock.close();
